""" URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/3.1/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.conf.urls import url
from django.urls import path, include
from django.views.decorators.cache import cache_page
from rest_framework.routers import DefaultRouter

from user_app.views import statistical, user, sku, permisson
from user_app.views.admin import AdminView
from user_app.views.group import GroupView
from user_app.views.image import ImageViewREST
from user_app.views.order import OrderView
from user_app.views.permisson import PermissionView

urlpatterns = [
    # ------------ 数据统计 -----------
    url('statistical/total_count/$',
        cache_page(60 * 3)(statistical.UserCount.as_view())),
    url('statistical/day_increment/$', statistical.IncrementUser.as_view()),
    url('statistical/day_active/$', statistical.DayActiveUser.as_view()),
    url('statistical/day_orders/$', statistical.DayOrderUser.as_view()),
    url('statistical/month_increment/$',
        statistical.MonthIncrementUser.as_view()),
    url('statistical/goods_day_views/$',
        statistical.GoodsDayViewCount.as_view()),

    # ----------- 用户管理 -----------
    url('user/$', user.UserList.as_view()),

    # ----------- 商品管理 -----------
    url('skus/$', sku.SKUView.as_view()),
    url('skus/(?P<pk>\d+)/$', sku.SKUView.as_view()),

    # ----------- 上传文件 ------------
    url('file/$', ImageViewREST.as_view({'get': 'list', 'post': 'create'})),
    path('file/<int:pk>/',
         ImageViewREST.as_view(
             {'get': 'retrieve', 'delete': 'destroy', 'put': 'update'})),

    # ------------ 订单 --------------
    path('orders/', OrderView.as_view({'get': 'list'})),
    path('orders/<int:pk>/', OrderView.as_view({'get': 'retrieve'})),
    path('orders/<int:pk>/<int:status>/', OrderView.as_view({'put': 'update'})),

    # ------------ 权限 ---------------
    path('permission/perms/',
         PermissionView.as_view({'get': 'list', 'post': 'create'})),
    path('permission/perms/<int:pk>/',
         PermissionView.as_view(
             {'get': 'retrieve', 'put': 'update', 'delete': 'destroy'})),
    path('permission/content_types/',
         PermissionView.as_view({'get': 'get_permission_contype'})),

    # ------------ 用户组 ----------------
    path('permission/groups/',
         GroupView.as_view({'get': 'list', 'post': 'create'})),
    path('permission/groups/<int:pk>/',
         GroupView.as_view(
             {'get': 'retrieve', 'put': 'update', 'delete': 'destroy'})),
    # 获取权限类型名称
    path('permission/simple/', GroupView.as_view({'get': 'simple'})),
]

# ------------ 管理员 --------------
router = DefaultRouter()
router.register('permission/admins', AdminView)
urlpatterns += [
    path('permission/admins/simple/', AdminView.as_view({'get': 'simple'})),
    path('', include(router.urls)),
]
